package com.nd.mobile.study.domain;

import java.io.Serializable;
import java.lang.reflect.Type;

import android.os.Bundle;

import com.fuckhtc.gson.Gson;
import com.fuckhtc.gson.annotations.SerializedName;
import com.fuckhtc.gson.reflect.TypeToken;
import com.nd.mobile.study.common.config.Commands;
import com.nd.mobile.study.common.config.ReqParam;
import com.nd.mobile.study.common.util.HttpRequestUtil;

public class ClassInfo implements Serializable{

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;

	@SerializedName("ClassesID")
	private String	id;

	@SerializedName("ClassesName")
	private String	name;

	@SerializedName("Description")
	private String	description;

	String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getDescr() {
		return description;
	}

	public ClassInfoCatalogRoot[] getCatalogRoot(User user) throws Exception {
		Bundle data = new Bundle();
		data.putString(ReqParam.ClassInfo.CLASSES_ID, this.id);
		data.putString(ReqParam.COMMON_USER_ID, user.getUserId());
		String jsonData = HttpRequestUtil.get(Commands.GET_CLASS_INFO_CATALOG_ROOT, data);
		Gson gson = new Gson();
		Type type = new TypeToken<Result<ClassInfoCatalogRoot[]>>() {
		}.getType();
		Result<ClassInfoCatalogRoot[]> result = gson.fromJson(jsonData, type);
		ClassInfoCatalogRoot[] body = result.getBody();
		for (ClassInfoCatalogRoot classInfoCatalogRoot : body) {
			classInfoCatalogRoot.setClassId(id);
		}
		return body;
	}

	public Subject[] getSubject(User user) throws Exception {
		Bundle data = new Bundle();
		data.putString(ReqParam.ClassInfo.CLASSES_ID, this.id);
		data.putString(ReqParam.COMMON_USER_ID, user.getUserId());
		String jsonData = HttpRequestUtil.get(Commands.GET_SUBJECT, data);
		Result<Subject[]> result = new Gson().fromJson(jsonData, new TypeToken<Result<Subject[]>>() {
		}.getType());
		Subject[] body = result.getBody();
		return body;
	}
	
}
